<template>
  <div>
    <Tou></Tou>
    <Second></Second>
    <template>
      <el-carousel indicator-position="none" height="450px">
        <el-carousel-item>
          <img src="https://www.12306.cn/index/images/pic/banner20201223.jpg">
        </el-carousel-item>
        <el-carousel-item>
          <img src="https://www.12306.cn/index/images/pic/banner20200707.jpg">

        </el-carousel-item>
        <el-carousel-item>
          <img src="https://www.12306.cn/index/images/pic/banner0619.jpg">
        </el-carousel-item>
        <el-carousel-item>
          <img src="https://www.12306.cn/index/images/pic/banner26.jpg">
        </el-carousel-item>
        <el-carousel-item>
          <img src="https://www.12306.cn/index/images/pic/banner10.jpg">
        </el-carousel-item>
        <el-carousel-item>
          <img src="https://www.12306.cn/index/images/pic/banner12.jpg">
        </el-carousel-item>
      </el-carousel>
    </template>
    <img src="../img/p2.png" alt="">
    <div>
      <img src="https://www.12306.cn/index/images/abanner01.jpg" alt="" style="width: 590px;">
      <img src="https://www.12306.cn/index/images/abanner02.jpg" alt="" style="width: 590px"><br>
      <img src="https://www.12306.cn/index/images/abanner03.jpg" alt="" style="width: 590px">
      <img src="https://www.12306.cn/index/images/abanner04.jpg" alt="" style="width: 590px">
    </div>
    <div style="width: 1188px;height: 100px;margin: 0 auto;background-image:url('https://dimg02.c-ctrip.com/images/10031e000001fq0hcB1E3.jpg_.webp');">
      <span style="font-size: 30px;line-height: 100px">酒店推荐>>>></span>
    </div>
    <div style="width: 1188px;margin: 0 auto">
      <el-row>
        <el-col :span="4" v-for="(o, index) in hotels" :key="o.hotelId" :offset="(index)%5 == 0 ? 0 : 1" style="margin-top: 10px">
          <el-card :body-style="{ padding: '0px' }">
            <img :src="o.hotelPic" class="image" style="width: 170px;height: 150px;margin-left: 12px;margin-top: 10px">
            <div style="padding: 14px;">
              <span>{{o.hotelName}}</span>
              <div class="bottom clearfix">
                <span class="time" style="margin-top: -10px">{{ o.hotelInfo }}</span><br>
                <span class="time" style="color:#aa0000;font-size: 15px;margin-left:-50px">¥{{ o.hotelPrice }}</span>
                <el-button type="text" class="button" @click="tofindbed(o.hotelId)">详情</el-button>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>
    <div style="width: 1188px;height: 100px;margin: 0 auto;background-color: #F4DDB5;">
      <span style="font-size: 30px;line-height: 100px">商品推荐>>>></span>
    </div>
    <div style="width: 1188px;margin: 0 auto">
      <el-row>
        <el-col :span="4" v-for="(o, index) in goods" :key="o.goodsId" :offset="(index)%5 == 0 ? 0 : 1" style="margin-top: 10px">
          <el-card :body-style="{ padding: '0px' }">
            <img :src="o.goodsPic1" class="image" style="width: 170px;height: 150px;margin-left: 12px;margin-top: 10px">
            <div style="padding: 14px;">
              <span>{{o.goodsName}}</span>
              <div class="bottom clearfix">
                <span class="time" style="margin-top: -10px">{{ o.goodsInfo }}</span><br>
                <span class="time" style="color:#aa0000;font-size: 15px;margin-left:-50px">¥{{ o.goodsPrice}}</span>
                <el-button type="text" class="button" @click="GoodsInfo(o.goodsId)">详情</el-button>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>
    <img src="../img/p4.png" alt="">
    <template>
      <el-tabs tab-position="left" style="height: 300px;" class="xuanze">
        <el-tab-pane label="车票" >
          <template>
            <div style="margin-top: 50px">
            <span style="font-size: 14px">出发地</span>
            <el-select v-model="start" placeholder="请选择">
              <el-option
                v-for="item in options1"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
            </div>
          </template>
          <template>
            <div>
            <span style="font-size: 14px">到达地</span>
            <el-select v-model="end" placeholder="请选择">
              <el-option
                v-for="item in options2"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
            </div>
          </template>
          <template>
            <div class="block">
              <span style="font-size: 14px">出发日期</span>
              <el-date-picker
                v-model="time1"
                type="date"
                placeholder="选择日期">
              </el-date-picker>
            </div>
          </template>
          <el-button type="primary" icon="el-icon-search" style="width: 200px; margin-top: 50px" @click="findCar">查询</el-button>
        </el-tab-pane>

        <el-tab-pane label="酒店" style="margin-top: 60px">
          城市 :
          <el-select v-model="city" placeholder="请选择城市">
            <el-option
              v-for="item in citys"
              :key="item.cityId"
              :label="item.cityName"
              :value="item.cityId">
            </el-option>
          </el-select>
          <el-button type="primary" icon= "el-icon-search" style="width: 150px; margin-top: 50px" @click="findhotel(city)">查询</el-button>
        </el-tab-pane>

        <el-tab-pane label="商城" >
          <el-button type="primary" icon="el-icon-search" style="width: 150px; margin-top: 110px;" @click="goGoods">去商城</el-button>
        </el-tab-pane>
      </el-tabs>
    </template>
  </div>
</template>

<script>
import Tou from "./tou.vue";
import Second from "./second.vue";

export default {
  name: "index",
  components: {Second, Tou},
  data() {
    return {
      input: '',
      activeIndex: '1',
      activeIndex2: '1',
      options1: [],
      options2: [],
      start: '',
      end:'',
      time1:'',
      currentDate: new Date(),
      hotels:[],
      goods:[],
      citys:[],
      city:''
    }
  },
  methods: {
  tofindbed(id){
    localStorage.setItem("hotelId",id)
    this.$router.push("/bed")
  },
    //酒店挂载
    loadHotel(){
      this.$axios.get('/hotel/findAll')
        .then(res=>{
          console.log(res.data.data)
          this.hotels=res.data.data
        })
    },
    loadGoods(){
      this.$axios.get('/goods/findAll')
        .then(res=>{
          console.log(res.data.data)
          this.goods=res.data.data
        })
    },
    //处理日期格式
    formatDate(dateString) {
      const date = new Date(dateString);
      const year = date.getFullYear();
      const month = (date.getMonth() + 1).toString().padStart(2, '0');
      const day = date.getDate().toString().padStart(2, '0');
      return `${year}-${month}-${day}`;
    },

    findCar(){
      if (!this.start) {
        // 检查是否已选择出发地、到达地和日期
        this.$message.error('请选择出发地');
      }else if (!this.end){
        this.$message.error('请选择到达地');
      }else if (!this.time1){
        this.$message.error('请选择时间');
      }
      else {
        this.time1 = this.formatDate(this.time1);//时间格式化
        this.$router.push({
          path: '/car',
          query: {
            start: this.start,
            end: this.end,
            time1: this.time1
          }
        })
      }
    },
    GoodsInfo(id){
      this.$router.push({path:'/goodsItem',query:{id:id}})
    },
    handleClick() {
      alert('button click');
    },
    handleSelect(key, keyPath) {
      console.log(key, keyPath);
    },
    loadStratAddr(){
      this.$axios.get('/car/findAllStarName').then(res=>{
        console.log(res.data.data)
        // 清空 options 数组
        this.options1 = [];
        // 遍历数据并将其添加到 options 数组
        res.data.data.forEach(item => {
          this.options1.push({ value: item, label: item });
        });
      })
    },
    loadEndAddr(){
      this.$axios.get('/car/findAllEndName').then(res=>{
        console.log(res.data.data)
        // 清空 options 数组
        this.options2 = [];
        // 遍历数据并将其添加到 options 数组
        res.data.data.forEach(item => {
          this.options2.push({ value: item, label: item });
        });
      })
    },
    findallcity() {
      this.$axios.get('/city/findallcitys').then(data=>{
        this.citys=data.data.data;
      })
    },
    findhotel(city){
      localStorage.setItem("city",city)
      this.$router.push("/hotel")
    },
    goGoods(){
      this.$router.push("/goods")
    }
  },
  mounted() {
    this.loadStratAddr();
    this.loadEndAddr();
    this.loadHotel();
    this.loadGoods();
    this.findallcity()
  }
}
</script>

<style scoped>
.sou {
  margin-top: 25px;
}

.el-dropdown {
  vertical-align: top;
}

.el-dropdown + .el-dropdown {
  margin-left: 15px;
}

.el-icon-arrow-down {
  font-size: 12px;
}

.centered-menu-item {
  display: flex;
  justify-content: center;
  background-color: #5199FD;
}

.el-menu--horizontal > .el-menu-item.is-active {
  border: none;
}

.daohang {
  margin-left: 60px;
  line-height: 60px;
}

.el-carousel__item h3 {
  color: #475669;
  font-size: 18px;
  opacity: 0.75;
  line-height: 300px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n+1) {
  background-color: #d3dce6;
}
.xuanze{
  position: absolute;
  left: 20%;
  top: 250px;
  background-color: #fff;
  z-index: 9;
  width: 500px;
}
.block {
  margin-left: -15px;
}
.time {
  font-size: 13px;
  color: #999;
}

.bottom {
  margin-top: 13px;
  line-height: 12px;
}

.button {
  padding: 0;
  float: right;
}

.image {
  width: 100%;
  display: block;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both
}
.bottom[data-v-47323bf2] {
  margin-top: 13px;
  line-height: 12px;
  display: contents
}
</style>
